<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<title>添加目标诊所</title>
    <script src="__JS__/zepto.min.js"></script>
    <link href="__CSS__/weui.min.css" rel="stylesheet">
	<link rel="stylesheet" href="__SaleManager__/stylesheets/index.css">
</head>
<style>
	.h_back{
		flex: 0.9!important;
	}
	.h_add{
	flex: 0.9!important;
	}
</style>
<body>
	<div class="addTargetClinic_w">
    <header class = "all_header">
      <a class = "h_back h_back_1" href="javascript:"><img src="__SaleManager__/images/back_icon.png" alt=""></a>
      <span class = "h_title">添加目标诊所</span>
      <a class = "h_add" href="javascript:void(0)"></a>
    </header>
    <form action='' name='addtargetclinic' id='addtargetclinic' method='post'>
		<div class="weui-cells__title">诊所名称</div>
		<div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input clinicName" type="text"  name='clinic_name' id='clinic_name' value='{$v.clinic_name}' placeholder="请输入诊所名称">
        </div>
      </div>
    </div>
    <div class="weui-cells__title">诊所联系人(选填)</div>
		<div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input clinicPeople" type="text" name='manager_name'  id='manager_name' value='{$v.manager_name}' placeholder="请输入诊所联系人">
        </div>
      </div>
    </div>
    <div class="weui-cells__title">电话(选填)</div>
		<div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input clinicTel" type="text" name='clinic_phone' id='clinic_phone' value='{$v.clinic_phone}'  placeholder="请输入电话">
        </div>
      </div>
    </div>
    <div class="weui-cells__title">地址</div>
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input clinicAdress" type="text" name='clinic_address' disabled  id='clinic_address' value='' placeholder="正在定位中，请等待...">
        </div>
      </div>
    </div>
    <input type="hidden" class="userkey" value="targetClinic{$myself.id}" />
        <input type="hidden" class="lng" value="" name='lng' id="lng"/>
        <input type="hidden" class="lat" value="" name='lat' id="lat"/>
<!--     <div class="weui-cells__title position_tips" style="display:block">正在定位中，请等待...</div> -->
</form>
		
    <div class="weui-btn-area">
      <a class="weui-btn add_btn" href="javascript:">确定</a>
    </div>
   <include file="./Application/Home/View/default/SaleManager/layer/popup.html"/> <!-- 弹出框 -->
	</div>
  <script src = "__SaleManager__/js/index.js"></script>
  <script src = "__SaleManager__/js/androidback.js"></script>
  <script>

  setTimeout(checkLocation, 100);
  function checkLocation() {
      var checkKey = $('.userkey').val();
      if (checkKey) {
          window.BSFWebView.showInfoFromJs(checkKey);
      }
  }

	$(document).on("click",".add_btn",function(){
		 var telReg = /^0?1[3|4|5|8][0-9]\d{8}$/;
		var clinicName = $(".clinicName").val()
		if (clinicName.trim().length == 0) {
			$("#confirm_dialog").show().find(".weui-dialog__bd").html("请输入诊所名称");
			return false;	
		}
		var clinicName = $(".clinicName").val(),
		manageerName = $('#manager_name').val(),
		clinicAdress = $('#clinic_address').val(),
		clinicPhone = $('#clinic_phone').val();

		if (telReg.test(clinicPhone) === false &&clinicPhone.trim().length > 0) { 
		$("#confirm_dialog").show().find(".weui-dialog__bd").html("手机号输入不合法");
		 return false;  
		};
		if (clinicName.trim().length == 0 || clinicAdress.trim().length == 0 ) {
			$("#confirm_dialog").show().find(".weui-dialog__bd").html("请输入名称或地址");
			return false;	
		}
		$.ajax({
            url: "",
            type: 'POST',
            data:{'lat':$('.lat').val(),'lng':$('.lng').val(),'clinic_name':$('#clinic_name').val(),'manager_name':$('#manager_name').val(),'clinic_phone':$('#clinic_phone').val(),'clinic_address':$('#clinic_address').val()},
            async: false,
            cache: false,
           /*  contentType: false, */
           /*  processData: false,  */
          	dataType:"json",
            success: function (returndata) {
            	　$('.weui-dialog__bd').html(returndata.msg);
          	  $('#confirm_dialog').css('display','block');
            },
            error: function (returndata) {
                alert(returndata);
            }
        });
		$(document).on('click','.weui-dialog__btn_primary',function(){

			location.href='/Home/SaleManager/County/targetClinic';
		});
  
	})
	//ajax定时
	var getAdd = setInterval("getAddress()",1000);//1000为1秒钟
	function getAddress(){  
		var uid='targetClinic{$myself.id}';
        $.ajax({  
            url:"/Home/Saleman/Public/getLatLngAddress",  
            type:"get",  
            async: false,
            cache: false,
           	data:{'uid':uid},
          	dataType:"json",
            success: function (returndata) {
            		if(returndata.code==1){
            			$('.lng').val(returndata.data.longitude);
            			$('.lat').val(returndata.data.latitude);
            			$('#clinic_address').val(returndata.data.address);
            			/* $('.position_tips').css('display','none'); */
            			clearInterval(getAdd);
            		}
            		checkLocation();
            },
            error: function (returndata) {
                alert(returndata);
            }
       	 }) 
    }  
	
	</script>
</body>
</html>